import requests

# url请求地址,data请求体数据,headers请求头信息
def post(url, data, headers = None) -> dict:
    try:
        response = requests.post(url, json=data, headers=headers, timeout=10)
        response.raise_for_status()
        return response.json()
    except requests.exceptions.RequestException as e:
        # 网络连接错误、超时
        return {"error": f"Request failed: {str(e)}"}
    except ValueError:
        # 解析响应内容为 JSON 格式时出现异常
        return {"error": "Invalid JSON response"}


